package com.dingup.paike.schedule;


import com.dingup.api.Util.DateUtil;
import com.dingup.paike.dao.PkLessonInfoMapper;
import com.dingup.paike.dao.PkLessonUserMapper;
import com.dingup.paike.dao.TsFeedbackContentMapper;
import com.dingup.paike.dao.TsFeedbackStudentEvaluateMapper;
import com.dingup.paike.feign.client.user.UserFeignClient;
import com.dingup.paike.model.feedback.SendMsg;
import com.dingup.paike.model.pk.PkLessonInfo;
import com.dingup.paike.model.pk.PkLessonUser;
import com.dingup.paike.service.message.DingTalkMsgService;
import com.dingup.paike.service.message.WxMsgService;
import com.dingup.paike.util.ConstUtil;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;

/**
 * Created by wancheng on 2018/6/21.
 */
@Component
public class FeedbackSchedule {


    private static final String URL_PARENT = "%s/feedback/detail/%s/%s";
    private static final String URL_CLASS_TEACHER = "%s/feedview/%s";
    private static final String COLOR = "#4e72b8";
    private static org.slf4j.Logger logger = LoggerFactory.getLogger(FeedbackSchedule.class);

    @Autowired
    WxMsgService wxMsgService;
    @Autowired
    TsFeedbackContentMapper tsFeedbackContentMapper;
    @Autowired
    TsFeedbackStudentEvaluateMapper tsFeedbackStudentEvaluateMapper;
    @Autowired
    PkLessonInfoMapper pkLessonInfoMapper;
    @Autowired
    UserFeignClient userFeignClient;
    @Autowired
    PkLessonUserMapper pkLessonUserMapper;
    @Autowired
    DingTalkMsgService dingTalkMsgService;






    public Boolean sendParentMsg(PkLessonInfo lesson, PkLessonUser student, String openId) throws ParseException {
        String url = String.format(URL_PARENT, ConstUtil.SYS_CONFIG_DATA.getInnerDomainName(), lesson.getId(), student.getUserId());
        SendMsg sendMsg = new SendMsg();
        sendMsg.setColor(COLOR);
        sendMsg.setUrl(url);
        sendMsg.setOpenId(openId);
        sendMsg.setFirst(student.getUserName() + " 家长，老师已经给您的孩子填写了昨日课程的反馈报告");
        sendMsg.setKeyword1(lesson.getLessonName());
        sendMsg.setKeyword2(DateUtil.date2Str(lesson.getBeginTime()) + " - " + DateUtil.getOnlyTimeFormatStr(lesson.getEndTime()));
        sendMsg.setKeyword3(student.getUserName());
        sendMsg.setRemark("感谢家长的支持！");
        Boolean ifSend = wxMsgService.sendFeedBackMsg(sendMsg);
        return ifSend;
    }

    /**
     * 检查是否是线上环境
     *
     * @throws Exception
     */
    private boolean isOfficialAddress() throws Exception {
       /* InetAddress address = InetAddress.getLocalHost();
        return address.getHostAddress().equals("10.27.32.237");*/
        return false;
    }
}
